package com.why.statistics.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.why.commonresults.Result;
import com.why.statistics.service.DailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author why
 * @since 2021-02-24
 */
@RestController
@RequestMapping("/statistics/")
@CrossOrigin
public class DailyController {
    @Autowired
    private DailyService dailyService;


    @PostMapping("{day}")
    public Result createStatisticsByDate(@PathVariable String day) {
        dailyService.createStatisticsByDay(day);
        return Result.ok();
    }

    @GetMapping("/showData/{type}/{begin}/{end}")
    public Result showStatisticsData(@PathVariable String begin,
                                     @PathVariable String end,
                                     @PathVariable String type) {

        Map<String, Object> result = dailyService.showDateByType(type, begin, end);

        return Result.ok().data(result);

    }

}

